package tech.aistar.day06;

/**
 * 本类用来演示: 银行账户类
 *
 * @author: success
 * @date: 2021/3/15 9:31 上午
 */
public class Account {
    private int id;

    private String accno;

    private double balance;

    public Account() {
    }

    public Account(int id, String accno, double balance) {
        this.id = id;
        this.accno = accno;
        this.balance = balance;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAccno() {
        return accno;
    }

    public void setAccno(String accno) {
        this.accno = accno;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "id=" + id +
                ", accno='" + accno + '\'' +
                ", balance=" + balance +
                '}';
    }

    /**
     * 存钱操作
     * @param money
     */
    public void saveMoney(double money){
        //参数校验
        if(money<=0){
            System.out.println("money不合法");
            return;
        }
        this.balance += money;
    }

    /**
     * 取钱
     * @param money
     */
    public void withDraw(double money){
        if(money<=0 || money>this.balance){
            System.out.println("money不合法!");
            return;
        }
        this.balance-=money;
    }
}

//一个类文件中只能定义一个public的类

//测试类
class TestAccount{
    public static void main(String[] args) {
        Account acc1 = new Account(1,"1001",100.0d);

        acc1.saveMoney(500.0d);
        acc1.withDraw(200.0d);
        System.out.println(acc1.getBalance());
    }
}